package domain;

import java.io.Serializable;

import exceptions.OverlappingPriceRangeException;

public class PriceStep implements Serializable {

	double startPrice;
	double endPrice;
	double fixedPrice;
	double variablePricePercent;
	
	public PriceStep(double startPrice, double endPrice, double fixedPrice, double variablePricePercent){
		this.startPrice = startPrice;
		this.endPrice = endPrice;
		this.fixedPrice = fixedPrice;
		this.variablePricePercent = variablePricePercent;
	}
	
	public double minPrice(){
		return startPrice;
	}
	
	public double maxPrice(){
		return endPrice;
	}
	
	public void checkOverlapping(double newStartPrice, double newEndPrice) throws OverlappingPriceRangeException{
		if(startPrice < newStartPrice && endPrice > newEndPrice){
			throw new OverlappingPriceRangeException("invalid Range!");
		} else if(newStartPrice < startPrice && newEndPrice > startPrice && newEndPrice < endPrice){
			throw new OverlappingPriceRangeException("new endPrice overlapping!");
		} else if(newStartPrice > startPrice && newStartPrice < endPrice && newEndPrice > endPrice){
			throw new OverlappingPriceRangeException("new startPrice overlapping!");
		} else if(newStartPrice < startPrice && newEndPrice > endPrice){
			throw new OverlappingPriceRangeException("total overlapping!");
		}
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "PriceStep [startPrice=" + startPrice + ", endPrice=" + endPrice
				+ ", fixedPrice=" + fixedPrice + ", variablePricePercent="
				+ variablePricePercent + "]";
	}

	/**
	 * @return the startPrice
	 */
	public double getStartPrice() {
		return startPrice;
	}

	/**
	 * @param startPrice the startPrice to set
	 */
	public void setStartPrice(double startPrice) {
		this.startPrice = startPrice;
	}

	/**
	 * @return the endPrice
	 */
	public double getEndPrice() {
		return endPrice;
	}

	/**
	 * @param endPrice the endPrice to set
	 */
	public void setEndPrice(double endPrice) {
		this.endPrice = endPrice;
	}

	/**
	 * @return the fixedPrice
	 */
	public double getFixedPrice() {
		return fixedPrice;
	}

	/**
	 * @param fixedPrice the fixedPrice to set
	 */
	public void setFixedPrice(double fixedPrice) {
		this.fixedPrice = fixedPrice;
	}

	/**
	 * @return the variablePricePercent
	 */
	public double getVariablePricePercent() {
		return variablePricePercent;
	}

	/**
	 * @param variablePricePercent the variablePricePercent to set
	 */
	public void setVariablePricePercent(double variablePricePercent) {
		this.variablePricePercent = variablePricePercent;
	}
	
	
}
